package com.cpi.cornpp.period.service;

import java.util.ArrayList;
import java.util.List;

import com.cpi.cornpp.period.converter.PeriodConverter;
import com.cpi.cornpp.period.dao.PeriodDAO;
import com.cpi.cornpp.period.exception.PeriodException;

public class PeriodService {
	
	public List getYears() throws PeriodException{
		PeriodDAO periodDAO = null;
		List years = null;
		try{
			periodDAO = new PeriodDAO();
			years = periodDAO.getYears();
		} catch(PeriodException periodException){
			throw periodException;
		}
		return years;
	}
	
	public List getActivePeriods() throws PeriodException{
		PeriodDAO periodDAO = null;
		PeriodConverter periodConverter = null;
		List activePeriods = null;
		
		activePeriods = new ArrayList();
		periodDAO = new PeriodDAO();
		periodConverter = new PeriodConverter();
		
		try{
			activePeriods = periodConverter.convertDTO(periodDAO.getPeriodsByStatus(1));
		} catch(PeriodException periodException){
			throw periodException;
		}
		
		return activePeriods;
	}
	/**
	 * Obtiene el periodo actual
	 * @return id de periodo
	 * @throws PeriodException
	 */
	public int actualPeriod()throws PeriodException{
		int actualPeriod = 0;
		PeriodDAO periodDAO = null;
		try{
			periodDAO = new PeriodDAO();
			actualPeriod = periodDAO.actualPeriod();
		}catch(PeriodException periodException){
			throw periodException;
		}
		return actualPeriod;
	}
}